home *** CD-ROM | disk | FTP | other *** search
/ Aminet 43 / Aminet 43 (2001)(GTI - Schatztruhe)[!][Jun 2001].iso / Aminet / text / edit / BareED.lha / BareED / rexx / GrabBareED.rx < prev    next >
Text File  |  2000-03-05  |  3KB  |  69 lines

  1. /*
  2. ;:ts = 4
  3.  
  4. A script to let the user choose to which running copy of BareED he/she would like
  5. to refer. Note: Currently only running copies of BareED from 1 to 9 become supported!
  6. To run this script you need the RequestChoice application in your C drawer,
  7. i.e. you need at least OS 3.0 ! 
  8.  
  9. */
  10.  
  11. IF ~EXISTS('C:RequestChoice') THEN
  12.     EXIT 50
  13.  
  14. CALL SETCLIP( 'BAREED', '0')
  15.  
  16. /* Get all public ports (in one single string) */
  17. PORT_STRING = SHOW('P')
  18.  
  19. /* Create a string that could look likes this: "BAREED.3|BAREED.4|BAREED.1|Cancel" */
  20. OFFSET = 0
  21. GADGET_LINE = '"'
  22. NUMBER_PORTS = 0
  23.  
  24. DO FOREVER
  25.     /* Get each port which starts with "BAREED." */
  26.     OFFSET = POS( 'BAREED.', PORT_STRING, OFFSET + 1)
  27.     IF OFFSET = 0 THEN
  28.         BREAK
  29.     ELSE
  30.         NUMBER_PORTS = NUMBER_PORTS + 1                                                /* Amount of ports remembered */
  31.         BAREED_NAME = SUBSTR( PORT_STRING, OFFSET, 8)                                /* 8 for BAREED.n */
  32.         BAREED_NAME = OVERLAY("|", BAREED_NAME, LENGTH(BAREED_NAME) + 1)            /* From »"BAREED.n« to »"BAREED.n|« */
  33.         GADGET_LINE = OVERLAY( BAREED_NAME, GADGET_LINE, LENGTH(GADGET_LINE) + 1)    /* From »"BAREED.n|« to »"BAREED.n|BAREED.n|« */
  34.     END
  35.  
  36. IF NUMBER_PORTS = 0 THEN DO    /* Opps, no running copy of BareED ! */
  37.     ADDRESS COMMAND            /* Let a CLI command do the work */
  38.     'C:RequestChoice >NIL: "BareED Grabber" "Missing a running copy of BareED.*NPlease start BareED manually and*Nthen restart this script!." "I will do it (maybe)"'
  39.     EXIT    20
  40.     END
  41.  
  42. GADGET_LINE = OVERLAY( 'Cancel"', GADGET_LINE, LENGTH(GADGET_LINE) + 1)                /* From »"BAREED.n|BAREED.n|« to »"BAREED.n|BAREED.n|Cancel"« */
  43.  
  44. ADDRESS COMMAND            /* Let a CLI command do the work */
  45. 'C:RequestChoice >T:BResult "BareED Grabber" "Enter the name of the port whose name*Nrepresents the running application that*Nyou would like to use for this script."' GADGET_LINE
  46.  
  47. BAREED_NUMBER = '0'        /* Default, in case 'T:BResult cannot be read */
  48.  
  49. IF OPEN('portnumber', 'T:BResult', 'R') THEN DO        /* Try to open T:BResult where RequestChoice dropped its result */
  50.     BAREED_NUMBER = READCH('portnumber', 1)            /* Read 0 for Cancel and any other value for usecount! */
  51.     CALL CLOSE 'portnumber'
  52.     'C:Delete >NIL: T:BResult'
  53.     END
  54.  
  55. IF BAREED_NUMBER = '0'    THEN                        /* If user cancelled... */
  56.     EXIT 5
  57.         ELSE DO
  58.     BAREED_NUMBER = BAREED_NUMBER - 1                /* Else, create index from given value */
  59.     END
  60.  
  61.     DEFAULT_BAREED = SUBSTR( GADGET_LINE,  BAREED_NUMBER * 9 + 2 , 8)    /* From index to string (port name) */
  62.  
  63. CALL SETCLIP( 'BAREED', DEFAULT_BAREED)    /*    Make variable BARRED available to other
  64.                                             AREXX applications which can use it as host, e.g.:
  65.                                                 BAREED_HOST = GetClip( 'BAREED')
  66.                                                 IF BAREED_HOST = '0' THEN EXIT
  67.                                                 ADDRESS VALUE BAREED_HOST */
  68. EXIT 0
  69.